package com.market2.utils.converter.impl;

import com.market2.dto.StockOptionDto;
import com.market2.model.StockOption;
import com.market2.utils.converter.Converter;

public class StockOptionConverter extends Converter
{
	@SuppressWarnings("unchecked") @Override
	public StockOptionDto convertTo(Object source)
	{
		if(source == null || !(source instanceof StockOption)) {
			return null;
		}
		
		StockOptionDto result = new StockOptionDto();
		StockOption stockOption = (StockOption) source;
		
		result.setNumero(stockOption.getNumero());
		result.setValeurUnitaire(stockOption.getValeurUnitaire());
		result.setQuantite(stockOption.getQuantite());
		
		if(stockOption.getTitulaire() != null) {
			result.setTitulaire(stockOption.getTitulaire().getLogin());
		}
		
		if(stockOption.getSociete() != null) {
			result.setSociete(stockOption.getSociete().getNom());
		}

		result.setDateEcheance(stockOption.getDateEcheance());
		return result;
	}

	@SuppressWarnings("unchecked") @Override
	public StockOption convertFrom(Object source)
	{
		if(source == null || !(source instanceof StockOptionDto)) {
			return null;
		}
		
		StockOption result = new StockOption();
		StockOptionDto stockOption = (StockOptionDto) source;
		
		result.setNumero(stockOption.getNumero());
		result.setValeurUnitaire(stockOption.getValeurUnitaire());
		result.setQuantite(stockOption.getQuantite());
		result.setDateEcheance(stockOption.getDateEcheance());
		
		return result;
	}
}
